<script >
import {listAll} from "@/api/kong/group";
import {goLive} from "@/api/kong/kong";

export default {
  data() {
    return {
      checkAll: false,
      checkedCities: [],
      isIndeterminate: false,
      groupList:[],
      formData:{
        groups:[],
        like1: 5,
        like2:10,
        num1: 10,
        num2:30
      },
      formData1:{
        groupNames:[],
        params: {
          selectControlIndex:3,
          exeMinSecond:3,
          exeMaxSecond:5,
          secondMinNum:1,
          secondMaxNum:10
        },
        cmdSetGid:5,
        actype:1
      },
      sumbmitLoading:false
    };
  },
  created() {
    this.groups();
  },
  methods: {
    handleCheckAllChange(val) {
      this.formData.groups = val ? this.groupList.map(item => item.groupName) : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.groupList.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.groupList.length;
    },
    likeAndFllows(value){

    },
    groups(keyword){
      this.loadinggroups = true
      const queryParams = {keyword:keyword};
      listAll(queryParams).then(response => {
        this.groupList = response.data;
      }).finally(() =>{
        this.loadinggroups = false
      });
    },
    onSubmit(cmdSetGid){
      if(this.formData1.groupNames.length===0){
        this.$modal.msgError("请选择要执行的组");
        return;
      }
      this.sumbmitLoading = true;
      if(cmdSetGid){
        if(cmdSetGid===-2){
          this.formData1.actype = -2 ;//停止命令
        }else{
          this.formData1.cmdSetGid = cmdSetGid;
        }
      }
      goLive(this.formData1).then(response => {
        this.$modal.msgSuccess("命令发送成功");
      }).finally(() =>{
        this.sumbmitLoading = false
        this.formData1.cmdSetGid = 5;
      });
    }
  }
};
</script>

<template>
  <div class="setcmd">
    <el-form ref="form" model="formData" label-width="120px">
      <el-form-item label="选择执行组" required>
        <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
        <el-checkbox-group v-model="formData1.groupNames" @change="handleCheckedCitiesChange">
          <el-checkbox v-for="city in groupList" :label="city.groupName" :key="city.gid" :value="city.groupName">{{city.groupName}}({{city.totalNum}})</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-divider content-position="left">抖音一键关注参数设置</el-divider>
      <el-form-item label="点赞时长" required>
        <el-row :gutter="9">
          <el-col :span="2">
            <el-input
              v-model="formData1.params.exeMinSecond">
            </el-input>
          </el-col>
          <el-col :span="0.5">到</el-col>
          <el-col :span="2">
            <el-input
              v-model="formData1.params.exeMaxSecond">
            </el-input>
          </el-col>
          <el-col :span="4">
            秒,持续点赞秒数范围(范围内随机)
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="每秒数量" required>
        <el-row :gutter="9">
          <el-col :span="2">
            <el-input
              v-model="formData1.params.secondMinNum">
            </el-input>
          </el-col>
          <el-col :span="0.5">到</el-col>
          <el-col :span="2">
            <el-input
              v-model="formData1.params.secondMaxNum">
            </el-input>
          </el-col>
          <el-col :span="4">
            个,每秒点赞数量范围(最多每秒10次,范围内随机)
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit(8)">立即点赞</el-button>
        <el-button type="danger" @click="onSubmit(-2)">停止点赞</el-button>
      </el-form-item>
    </el-form>
    <el-divider content-position="left">抖音一键关注参数设置</el-divider>
    <el-form ref="form"  model="formData1" label-width="120px">
      <el-form-item label="关注选择" required>
        <el-radio v-model="formData1.cmdSetGid" :label="5" >关注主播</el-radio>
        <el-radio v-model="formData1.cmdSetGid" :label="6">关注榜几</el-radio>
        <el-radio v-model="formData1.cmdSetGid" :label="7">关注前几</el-radio>
      </el-form-item>
      <el-form-item label="榜几/前几" required>
        <el-input
          v-model="formData1.params.selectControlIndex">
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit(5)" :loading="sumbmitLoading">立即关注</el-button>
        <el-button type="danger" @click="onSubmit(6)" :loading="sumbmitLoading">取消关注</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<style scoped lang="scss">
.setcmd{
  margin: 10px;
}
.el-col {
  text-align: center;
}
</style>
